package com.song.hbasechap_7_6;

import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class MapperManger {

	//bcd2051e-1cc9-420f-8e47-26bebdc9ba01:1458920357715	col:test4:9
	public  static Map<String,Put> StringToPut(String line)
	{
		
		Map<String,Put> map = new HashMap<String, Put>();
		String[] seg = line.split("\t");
		String rowstr = seg[0];
		String valstr = seg[1];
		
		String[] rowkeyseg = rowstr.split(":");
		String rowkeystr = rowkeyseg[0];
		String tsstr = rowkeyseg[1];
		long ts = Long.parseLong(tsstr);
		
		
		String[] valseg = valstr.split(":");
		
		String family = valseg[0];
		String col = valseg[1];
		String val =valseg[2];
		
		Put put = new Put(Bytes.toBytes(rowkeystr)  , ts);
		put.add(Bytes.toBytes(family) , Bytes.toBytes(col) ,Bytes.toBytes( val));
		map.put(rowkeystr, put);
		return map;
	}
	
	//col_test2_99247_1458920358372	ffe4c0fa-e45b-48ea-8b69-c4d5d0daa06a
	public static Map<String,Put> StringToIndexPut(String line)
	{
		Map<String,Put> map = new HashMap<String, Put>();
		String[] seg = line.split("\t");
		String rowstr = seg[0];
		String valstr = seg[1];
		
		String[] rowkeyseg = rowstr.split("_");
		String tsstr = rowkeyseg[3];
		String rowkeystr = rowstr.replace("_"+tsstr, "");
		long ts = Long.parseLong(tsstr);
		
		Put put = new Put(Bytes.toBytes(rowkeystr)  , ts);
		put.add(Bytes.toBytes("index") , Bytes.toBytes("data") ,Bytes.toBytes( valstr));
		map.put(rowkeystr, put);
		return map;
	}
	
	public static void main(String[] args) {
		
		StringToIndexPut("col_test2_99247_1458920358372	ffe4c0fa-e45b-48ea-8b69-c4d5d0daa06a");
	}
	
}
